﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OrzEntityConsoleApplication.YourEntity;

namespace OrzEntityConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            if (EmployeeEntity.DefaultDirectory.Exists)
            {
                EmployeeEntity.CleanDirectory();
            }
            if (ProjectEntity.DefaultDirectory.Exists)
            {
                ProjectEntity.CleanDirectory();
            }
            ProjectEntity[] projects = new ProjectEntity[3];

            for (int i = 0; i < projects.Length; i++)
            {
                projects[i] = new ProjectEntity();
                projects[i].Modified = true;
                projects[i].ProjectItem = "Project" + DateTime.Now;
                projects[i].SaveIfModified();              
            }

            var e = new EmployeeEntity();
            e.FirstName = "Jerry";
            e.LastName = "Liang";
            e.ProjectAssigned = new List<ProjectEntity>();
            e.ProjectAssigned.AddRange(projects);
            e.Save();
            e.ProjectAssigned[0].ProjectItem = "new";
            e.ProjectAssigned[0].ProjectDetails = "this is a new project";
            e.Save();

            var m = new ManagerEntity();
            m.Carspace = "Hello";
            m.FirstName = "test";
            m.Modified = true;
            m.SaveIfModified();

            e.DirectManager = m;
            e.Save();



      

            foreach (var employeeEntity in EmployeeEntity.List<EmployeeEntity>())
            {
                if (employeeEntity.DirectManager != null)
                {
                    Console.WriteLine(employeeEntity.DirectManager.Carspace);
                }
            }

            Console.Read();
        }
    }
}
